package com.inhim.pjhim.adapter.provider;

import android.content.Context;
import android.content.Intent;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chaychan.adapter.BaseItemProvider;
import com.inhim.pjhim.R;
import com.inhim.pjhim.activity.ArticleActivity;
import com.inhim.pjhim.activity.RadioActivity;
import com.inhim.pjhim.activity.VideoActivity;
import com.inhim.pjhim.adapter.TagReaderListAdapter;
import com.inhim.pjhim.entity.TagReaderList;
import com.inhim.pjhim.utils.ImageLoaderUtils;
import com.inhim.pjhim.view.CustomRoundAngleImageView;

import fm.jiecao.jcvideoplayer_lib.JCUtils;

/**
 * @author ChayChan
 * @description: 头部banner
 * @date 2018/3/22  14:48
 * 未使用
 */

public class ReaderTagItemProvider extends BaseItemProvider<TagReaderList.Reader, BaseViewHolder> {

    private Context context;
    public ReaderTagItemProvider(Context context) {
        this.context=context;
    }

    @Override
    public void convert(BaseViewHolder helper, final TagReaderList.Reader data, int i) {
        if (data == null) {
            //如果没有标题，则直接跳过
            return;
        }
        CustomRoundAngleImageView iv_title =helper.getView(R.id.iv_title);
        TextView tv_title = helper.getView(R.id.tv_title);
        TextView tv_content=helper.getView(R.id.tv_content);
        TextView tv_time1=helper.getView(R.id.tv_time1);
        TextView tv_time=helper.getView(R.id.tv_time);
        TextView textview2=helper.getView(R.id.textview2);
        ConstraintLayout lin_1=helper.getView(R.id.constran);
        lin_1.setOnClickListener(v -> {
            Intent intent;
            if(data.getType()==2){
                intent=new Intent(context, VideoActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            }else if(data.getType()==3){
                intent=new Intent(context ,RadioActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            }else{
                intent=new Intent(context, ArticleActivity.class);
            }
            intent.putExtra("ReaderId",data.getReaderId());
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivity(intent);
        });
        try{
            tv_content.setText(data.getContent());
            ImageLoaderUtils.setImage(data.getCover(),iv_title);
            tv_title.setText(data.getTitle());
            if(data.getTagName()==null || "".equals(data.getTagName())){
                textview2.setVisibility(View.GONE);
            }else{
                textview2.setVisibility(View.VISIBLE);
                textview2.setText(data.getTagName());
            }
            //tv_content.setText("上传时间:"+data.getCreateTime());
            if(data.getAuthor()!=null && data.getAuthor().getName()!=null){
                tv_time1.setText("作者:" + data.getAuthor().getName());
            }else{
                tv_time1.setText("作者:");
            }
            tv_time1.setVisibility(View.GONE);
            //1文章 2视频 3音频
            if(data.getType()==1){
                tv_time.setVisibility(View.GONE);
            }else{
                if(data.getDuration()!=null){
                    tv_time.setVisibility(View.VISIBLE);
                    tv_time.setText("时长 "+JCUtils.stringForTime2(Integer.valueOf(data.getDuration())));
                }else{
                    tv_time.setText("时长 00:00");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    private void setText(TextView textView,String content){
        if(content!=null&&textView!=null){
            textView.setText(content);
        }
    }

    @Override
    public int viewType() {
        return TagReaderListAdapter.READER;
    }

    @Override
    public int layout() {
        return R.layout.item_project_list;
    }

}
